/* 
 * Copyright (c)	Insighten Intelligent Equipment co.,LTD
 * 
 *  Use of this software is controlled by the terms and conditions found
 *  in the license agreement under which this software has been supplied.
 * 
 */
/** 
 * @file udp_svr_main.c
 * @brief udp library for create socket
 * @author taco [tacoee@gmail.com]
 * @version 0.1
 * @date 2010-09-06
 */
#include <stdlib.h>
#include <stdio.h>

#include "udp_lib.h"
#include "rwbuf.h"
#include "sock_util.h"

void helper(char *program)
{
	fprintf(stderr,"Usage: %s address[192.168.1.xxx] port[1234]\n", program);
}

int main(int argc, char *argv[])
{
	UdpSocket *udp_svr = NULL;
	RwBuf	*buf = NULL;
	SocketAttr attr={1, 8192};
	int port;

	if (argc < 3) {
		helper(argv[0]);
		exit(1);
	}
	port = atoi(argv[2]);

	buf = buf_new(NULL, NULL);
	buf_init(buf, 1024);

	udp_svr = udp_socket_new();

	udp_socket_init(udp_svr, "0.0.0.0", argv[1], port, &attr);
	udp_socket_buf_init(udp_svr, buf);

	udp_socket_create_bind(udp_svr);
	udp_socket_connet(udp_svr);

	buf_destroy(buf);
	udp_socket_destroy(udp_svr);

	return 0;
}

